//
//  HJCWelcomeViewController.swift
//  新浪微博Swift
//
//  Created by 郝俊聪 on 15/5/13.
//  Copyright (c) 2015年 heima. All rights reserved.
//

import UIKit
import SDWebImage

class HJCWelcomeViewController: UIViewController {

    @IBOutlet weak var avatarView: UIImageView!
    
    @IBOutlet weak var welcomeLbl: UILabel!
    
    @IBOutlet weak var imageViewConstraint: NSLayoutConstraint!
    
    override func viewDidLoad()
    {
        super.viewDidLoad()
        
        //切割iamgeview为圆形
        avatarView.layer.cornerRadius = avatarView.frame.size.height/2
        avatarView.layer.masksToBounds = true
        
        
        //设置头像
        if let imageName = sharedaccount?.avatar_large{
            
            avatarView.sd_setImageWithURL(NSURL(string: imageName))
            
        }
        
        //设置欢迎文字
        if let textName = sharedaccount?.name{
            
           welcomeLbl.text = "欢迎回来，\(textName)"
        
        }
        
        welcomeLbl.alpha = 0
        
    }
    
    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
        
        setAnimation()
    }
    
    private func setAnimation()
    {
        imageViewConstraint.constant = self.view.frame.size.height - imageViewConstraint.constant
        
        
        UIView.animateWithDuration(1, delay: 0, usingSpringWithDamping: 0.5, initialSpringVelocity: 5, options: nil, animations: { () -> Void in
            
            self.view.layoutIfNeeded()
            
            
        }) { (_) -> Void in
            
            UIView.animateWithDuration(0.5, animations: { () -> Void in
               self.welcomeLbl.alpha = 1
            }, completion: { (_) -> Void in
                
                //通知切换控制器
                NSNotificationCenter.defaultCenter().postNotificationName(NSSWICTHCONTRONLLERNOTIFICATION, object: "Main")
            })
            
        }
        
    }

    
}
